<?php
// 生成 Ed25519 密钥对
$keypair = sodium_crypto_sign_keypair();
$privateKey = sodium_crypto_sign_secretkey($keypair);
$publicKey = sodium_crypto_sign_publickey($keypair);

// Base64 编码
$privateKeyBase64 = base64_encode($privateKey);
$publicKeyBase64 = base64_encode($publicKey);
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>Ed25519密钥对生成器</title>
    <style>
        body { font-family: "微软雅黑", Arial, sans-serif; background: #f5f7fa; padding: 40px; }
        .box { background: #fff; border-radius: 8px; padding: 30px; max-width: 600px; margin: auto; box-shadow: 0 2px 8px #0001; }
        h2 { color: #2d8cf0; }
        textarea { width: 100%; height: 60px; font-size: 16px; margin-bottom: 20px; }
        .tip { color: #888; font-size: 14px; }
    </style>
</head>
<body>
<div class="box">
    <h2>Ed25519 密钥对生成器</h2>
    <div>
        <b>私钥（Base64，生成JWT用，务必妥善保存！）</b>
        <textarea readonly><?php echo htmlspecialchars($privateKeyBase64); ?></textarea>
    </div>
    <div>
        <b>公钥（Base64，粘贴到和风天气后台凭据管理）</b>
        <textarea readonly><?php echo htmlspecialchars($publicKeyBase64); ?></textarea>
    </div>
    <div class="tip">
        每次刷新页面都会生成一对新的密钥对。<br>
        <b>私钥只保存在本地，千万不要泄露！</b><br>
        公钥可放心粘贴到和风天气后台新建凭据时的“公钥”输入框。
    </div>
</div>
</body>
</html>